<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="common/head.jsp"%>
<div class="layui-body">
    <div style="padding: 15px;">
    <form class="layui-form">
        <blockquote class="layui-elem-quote">基本信息</blockquote>
        <div class="layui-form-item">
            <label class="layui-form-label">用户ID</label>
            <div class="layui-input-inline">
                <input type="text" name="userID" disabled="disabled" placeholder="" class="layui-input" id="userCode">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userID" disabled="disabled" placeholder="" class="layui-input" id="userName">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">绑定微信</label>
            <div class="layui-input-block layui-word-aux">
                <a class="layui-btn" id="weixin"><i class="layui-icon layui-icon-login-wechat" style="font-size: 24px;"></i>绑定微信</a>
                 绑定后第一时间  get  最新审批消息
            </div>
        </div>
        <blockquote class="layui-elem-quote">修改密码</blockquote>
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input autocomplete="new-password" type="password" name="password" minlength="8" maxlength="16"
                       oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input" id="input_oldpwd">
            </div>
            <div style="color: red; font-size: larger;">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input autocomplete="new-password" type="password" name="password" minlength="8" maxlength="16"
                       oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input" id="input_newpwd">
            </div>
            <div style="color: red; font-size: larger;">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input autocomplete="new-password"  type="password" name="password" minlength="8" maxlength="16"
                       oninput="value=value.replace(/[^\a-\z\A-\Z0-9\+\-\_\!\@\#\$\%\^\&\*\.]/g,'')" required lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input" id="input_againpwd">
            </div>
            <div style="color: red; font-size: larger;">*</div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button  id="button_modify" class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
            </div>
        </div>
    </form>
    </div>
</div>
<%@include file="/jsp/user/common/foot.jsp" %>
<%--引入jform库--%>
<script type="text/javascript" src="<%=path%>/js/jquery-form.js"></script>
<script type="text/javascript">
    /*小提示*/
    $('#input_oldpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请输入原密码'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('#input_newpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请设置8-16位新密码，可包括英文大小写、数字、特殊字符!@#$%^&*_+-.'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('#input_againpwd').on('click', function(){
        let that = this;
        layer.tips("<span style='font-size:14px'>"+'请再输一遍新密码'+"</span>", that,{ tips: [2, '#009688'],time:3000});
    });
    $('.layui-form').on('submit', function () {
        let oldpwd = $('#input_oldpwd').val();
        let newpwd = $('#input_newpwd').val();
        let againpwd = $('#input_againpwd').val();

        /*表单输入验证*/
        if (oldpwd.length < 8 || newpwd.length < 8 || againpwd.length < 8) {
            layui.use('layer',function () {
                var layer=layui.layer;
                layer.alert("输入密码位数不足8位，请重新输入！");
            })
            $('#input_oldpwd').val("");
            $('#input_newpwd').val("");
            $('#input_againpwd').val("");
        } else if (newpwd == againpwd) {
            if (newpwd == '00000000'){
                layer.alert("不能和初始密码一致，请重新设置！");
                $('#input_newpwd').val("");
                $('#input_againpwd').val("");
            }else if (newpwd == oldpwd){
                layer.alert("新密码不能和旧密码一致，请重新设置！");
                $('#input_newpwd').val("");
                $('#input_againpwd').val("");
            } else {
                $.ajax({
                    type: "POST"
                    , url: '${pageContext.request.contextPath}/jsp/user.do?method=pwdModify&oldpwd=' + oldpwd + '&newpwd=' + newpwd
                    , data: 'json'
                    , success: function (data) {
                        if (data.ok == "yes") {
                            layui.use('layer',function () {
                                alert("密码修改成功，请重新登录！");
                            })
                            window.location.href = "${pageContext.request.contextPath}/jsp/logout.do";
                        } else {
                            layui.use('layer',function () {
                                var layer=layui.layer;
                                layer.alert("原密码错误！");
                            })
                            $('#input_oldpwd').val("");
                            $('#input_newpwd').val("");
                            $('#input_againpwd').val("");
                        }
                    }
                });
            }
        } else {
            alert("确认密码与新密码不一致！");
            $('#input_newpwd').val("");
            $('#input_againpwd').val("");
        }
        return false;
    });
</script>
<script type="text/javascript">
    $('#weixin').on('click',function () {
        $.ajax({
            type:'POST'
            ,url: '${pageContext.request.contextPath}/weixin.do?method=bind'
            ,dataType:'json'
            ,success:function (data) {
                if (data!=null && data.code == 200){
                    window.open(data.url,"_blank");
                }if (data!=null && data.code == 300){
                    layer.msg('您已绑定微信。若要解绑，请前往 西安科技大学实验室资源申请平台（LMS）公众号 解除绑定！');
                }if(data!=null && data.code == 404){
                    layer.msg('服务异常，绑定失败');
                }
            }
        })
    })
</script>
</body>
</html>